package com.design.softwaredesign.controller;

import com.design.softwaredesign.entity.User;
import com.design.softwaredesign.front.UserInfo;
import com.design.softwaredesign.service.BackUserService;
import com.design.softwaredesign.vo.DataVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author :WaiterXiaoYY
 * @description: TODO
 * @data :2020/11/4 16:07
 */
@Api(description = "管理员接口控制层-用户控制")
@RestController
@RequestMapping("/web/admin")
public class BackUserController {

    @Autowired
    private BackUserService backUserService;

    @ApiOperation(value = "获取全部用户信息")
    @GetMapping("/getalluser")
    public DataVo getUserInfo(String query,  Integer pageNum, Integer pageSize, Integer userState) {
        DataVo dataVo = new DataVo();
        dataVo = backUserService.getUserInfo(query, pageNum, pageSize, userState);
        return dataVo;
    }

    @ApiOperation(value = "添加测试用户")
    @PostMapping("/adduser")
    public DataVo addUser(@RequestBody UserInfo userInfo) {
        DataVo dataVo = new DataVo();
        dataVo = backUserService.addUser(userInfo);
        return dataVo;
    }

    @ApiOperation(value = "更改用户信息")
    @PostMapping("/updateuserinfo")
    public DataVo updateUserInfo(@RequestBody User user) {
        DataVo dataVo = new DataVo();
        dataVo = backUserService.updateUserInfo(user);
        return dataVo;
    }

    @ApiOperation(value = "删除用户")
    @DeleteMapping("/deleteuser/{userId}")
    public DataVo deleteUser(@PathVariable String userId) {
        DataVo dataVo = new DataVo();
        dataVo = backUserService.deleteUser(userId);
        return dataVo;
    }
}
